package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class LoginServlet3
 */
@WebServlet("/LoginServlet3")
public class LoginServlet3 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet3() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");    //设置输入内容的编码方式
		
		response.setContentType("text/html;charset=UTF-8");   //设置为html编码格式
		
		String username=request.getParameter("username");
		
		
		String password=request.getParameter("password");
		

		HttpSession session=request.getSession();
		session.setAttribute("username", username);
		
		session.setMaxInactiveInterval(60); //60s  单位是秒 时间周期，过了时间，session失效
		//                                时间是从最后一次操作开始计算
		
		//Request  请求
		//Session  会话   对应一个用户
		//ServletContext  应用/容器上下文
		
		//生命周期 ServletContext>Session>Requset
		//传值选择-->Request-->Session-->ServletContext	
		
		response.sendRedirect("IndexServlet3");		//重定向	
	}


}
